package test.entity;

import java.util.List;

public class SuperMarket {

    private final Integer quota = 100;//满100减10块

    private final Integer discount = 10;

    private boolean open = false;

    public void setOpen(boolean open) {
        this.open = open;
    }

    public Double getPrices(List<Product> products){
        double prices = 0.0;
        for(Product product : products){
            if(product instanceof Strawberries){
                Strawberries strawberries = (Strawberries)product;
                if(strawberries.getDiscount() != 0){
                    prices = prices + strawberries.getPrice()*strawberries.getDiscount()*strawberries.getWeight();
                }else{
                    prices = prices + strawberries.getPrice()*strawberries.getWeight();
                }

            }else {
                prices = prices + product.getPrice()* product.getWeight();
            }
        }
        if(open && prices >= quota){
            prices = prices - discount ;
        }
        return prices;
    }

}
